<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .big-box {
            margin: 50px;
        }

        h2 {
            text-align: center;
            font-weight: 700;
            line-height: 80px;
        }

        .big-box input {
            box-sizing: border-box;
            padding-left: 30px;
            width: 100%;
            height: 40px;
            border-radius: 5px;
            margin: 20px auto;
        }

        .big-box span {
            position: fixed;
            left: 220px;
            color: aqua;
        }

        .big-box button {
            height: 50px;
            width: 100%;
            background-color: blue;
        }
    </style>
</head>

<body>
    <div class="big-box">
        <h2>注册新账号</h2>
        <input type="text" placeholder="输入账号"><br>
        <input type="password" placeholder="输入密码"><br>
        <input type="password" placeholder="确认密码"><br>
        <span>忘记密码？</span><br>
        <button>登录页</button>
    </div>
</body>

</html>
<script src="./04-ajax.js"></script>
<script>
    var inps = document.querySelectorAll('input')
    var btn = document.querySelector('button')
    btn.onclick = function () {
        if (inps[0].value && inps[1].value && inps[2].value) {
            if ((/^1[3-9]\d{9}$/.test(inps[0].value) || /\w{4,8}/.test(inps[0].value)) && /^\d{4}$/.test(inps[1].value) && inps[1].value == inps[2].value) {
                ajax('get', 'https://yantianfeng.com/api/register', { username: inps[0].value, password: inps[1].value }, function (data) {
                    if (data.status == 200) {
                        console.log('注册成功');
                    } else {
                        console.log('注册失败!');
                    }
                })
            } else {
                alert('请输入正确的账号/密码')
            }
        } else {
            alert('账号/密码/确认密码不能为空！')
        }
    }
</script>